package com.huawei.java.main.classes;

public class ServerNode {
    private final int cpu;
    private final int memory;
    private int currentCpu;
    private int currentMemory;

    protected ServerNode(int cpu, int memory) {
        this.cpu = cpu;
        this.memory = memory;
        this.currentCpu = cpu;
        this.currentMemory = memory;
    }

    protected void add(int cpu, int memory) {
        currentCpu -= cpu;
        currentMemory -= memory;
        if (currentCpu < 0) {
            throw new UnknownError("cpu out");
        } else if (currentMemory < 0) {
            throw new UnknownError("memory out");
        }
    }

    protected void del(int cpu, int memory) {
        currentCpu += cpu;
        currentMemory += memory;
    }

    public int getCpu() {
        return cpu;
    }

    public int getMemory() {
        return memory;
    }

    public int getCurrentCpu() {
        return currentCpu;
    }

    public int getCurrentMemory() {
        return currentMemory;
    }
}
